$def with(form, saved=None)
$:render.admin.header(scripts=['scripts/libs/jquery.tools.min.js','scripts/libs/fancybox/jquery.fancybox-1.3.4.pack.js','admin/scripts/tinymce/jquery.tinymce.js','admin/scripts/tinymce/wp/wp-fullscreen.js','admin/scripts/tinymce/wp/wplink.js','admin/scripts/tinymce/init.js','admin/scripts/core.js'],css=['admin/css/ui.css','scripts/libs/fancybox/jquery.fancybox-1.3.4.css','admin/scripts/thickbox/thickbox.css'])

<script type="text/javascript">
    $$(function () {
        $$('._fancybox').fancybox({
                'autoScale': true,
                'type': 'iframe',
                'width': 670,
                'height': 388
            });
        $$('#validator_link').fancybox();
        form_validator();
        $$('#thumbnail a').click(delete_media);
        $if form.proj_type.value:
            set_related_comp_item($form.proj_type.value);
    });
    function form_validator() {
        $$.tools.validator.addEffect('wall', function(errors, event) {
            // 获取错误容器
            var wall = $$(this.getConf().container);
            // 移除所有已经有的信息
            wall.find('p').remove();
            // 附加么一条信息
            $$.each(errors, function(index, error) {
                // 附加错误信息到容器中
                wall.append(
                    '<p>' + (index + 1) + '. ' + error.messages[0] + '</p>'
                );
                // 在错误控件上，添加一个标识无效的class
                error.input.addClass('invalid');
            });
            $$('#validator_link').trigger('click');

        }, function(inputs) {
            // 该方法中处理输入有效的控件
            $$.each(inputs, function(index, input) {
                // 去掉标识无效的class
                $$(input).removeClass('invalid');
            });
        });
        $$('form').validator({
                'messageAttr': 'message',
                'effect': 'wall',
                'container': '#errors'
        });
        $$(':date').dateinput({'format':'yyyy-mm-dd'});
    };
    var media_ids = [];
    $if form.media_id.value:
        media_ids = '$form.media_id.value'.split(',');
    // media uploader callback
    function media_selected(id, thumbnail) {
        if (id > 0) {
            media_ids.push(id.toString());
            //$$('#media_id').val(id.toString());
            var img = $$('<a href="javascript:;" title="重击删除" related="' + id + '"><img src="' + thumbnail + '" /></a>');
            var t = $$('#thumbnail');
            t.show();
            t.append(img);
            $$.fancybox.close();
            // reset media ids
            img.click(delete_media);
            reset_media_val();
        }
    };
    function proj_selected(id, name, type) {
        if (id > 0) {
            $$('#proj_id').val(id.toString());
            var sproj = $$('#sproj');
            sproj.show();
            sproj.html('已选择：<font color="red"><strong>' + name + '</strong></font>');
            $$.fancybox.close();
            set_related_comp_item(type);
        }
    };
    function partner_selected(id, name) {
        if (id > 0) {
            $$('#partner_id').val(id.toString());
            var spartner = $$('#spartner');
            spartner.show();
            spartner.html('已选择：<font color="red"><strong>' + name + '</strong></font>');
            $$.fancybox.close();
        }
        
    };
    function delete_media() {
        var el = $$(this);
        var related = el.attr('related');
        el.remove();
        media_ids.removeBy(related);
        reset_media_val();
    };
    function reset_media_val() {
        $$('#media_id').val(media_ids.join(','));
    };
    var related_comp_items = {
        '1': {'url': 'hotel', 'text':'酒店'}
    };
    function set_related_comp_item(type) {
        if (related_comp_items[type]) {
            var item = related_comp_items[type];
            //$$('#related_comp_container').show();
            var itemEL = $$('#related_comp_item');
            var gp = itemEL.parent().parent();
            gp.show();gp.prev().show();
            itemEL.attr('href', '$config.ADMIN_DIR/' + item.url + '?mode=lite');
            itemEL.html('设置关联' + item.text + '比价');
        }
    };
    var thickboxL10n = {"next":"\u4e0b\u4e00\u9875 >","prev":"< \u4e0a\u4e00\u9875","image":"\u56fe\u50cf","of":"\/","close":"\u5173\u95ed","noiframes":"\u8fd9\u4e2a\u529f\u80fd\u9700\u8981 iframe \u7684\u652f\u6301\u3002\u60a8\u53ef\u80fd\u7981\u6b62\u4e86 iframe \u7684\u663e\u793a\uff0c\u6216\u60a8\u7684\u6d4f\u89c8\u5668\u4e0d\u652f\u6301\u6b64\u529f\u80fd\u3002","loadingAnimation":"/static/admin/scripts/thickbox/loadingAnimation.gif","closeImage":"/static/admin/scripts/thickbox/tb-close.png"};
</script>
<script type="text/javascript" src="/static/admin/scripts/thickbox/thickbox.js"></script>

<a href="#errors" style="display:none;" id="validator_link"></a>
<div id="error_container" style="display:none;">
    <div id="errors">
        <h2>请先修复以下问题</h2>
    </div>
</div>
<div class="itemtitle">
    <h3>$:form.submit.attrs['html']</h3>
    <ul class="tab1">
        <li><a href="$config.ADMIN_DIR/discount"><span>管理</span></a></li>
        <li class="current"><a href="$config.ADMIN_DIR/discount/add"><span>添加</span></a></li>
    </ul>
</div>
$if saved:
    <div style="color:#ff0000;">保存成功！！</div>
<form method="post" action="">
<table class="tb tb2">
    <tr><td class="td27" colspan="2">信息地址(URL)：</td></tr>
    <tr class="noborder">
        <td class="vtop rowform">$:form.url.render()</td>
        <td class="vtop tips2">请给出该特惠信息所对应的合作方提供的信息完整地址（订购地址）。</td>
    </tr>
    <tr><td class="td27" colspan="2">过期时间：</td></tr>
    <tr class="noborder">
        <td class="vtop rowform">$:form.expire.render()</td>
        <td class="vtop tips2">可选，当日期到达此日期时，特惠信息详情，将会显示一段醒目的文字提示。</td>
    </tr>
    <tr>
        <td class="td27">闪电特惠：$:form.lightning.render()</td>
        <td class="vtop tips2">闪电特惠表示该特惠信息有可能在短期内产生剧烈变化的信息，如：到期或特惠价格取消等。</td>
    </tr>
    <tr>
        <td class="td27">直销特惠：$:form.directing.render()</td>
        <td class="vtop tips2">直销特惠表示该特惠信息由酒店、航空公司等官方机构直接提供的特惠信息。</td>
    </tr>
    <tr><td class="td27" colspan="2">标题：</td></tr>
    <tr class="noborder">
        <td class="vtop rowform">$:form.title.render()</td>
        <td class="vtop tips2">标题长度请控制在16个汉字，32个字符以内。</td>
    </tr>
    <tr><td class="td27" colspan="2">价格：</td></tr>
    <tr class="noborder">
        <td class="vtop rowform">$:form.price.render()
            <label>
                $:form.is_initial_price.render()
                <font style="vertical-align:middle;">起价</a>
            </label>
        </td>
        <td class="vtop tips2">价格必须输入整数。</td>
    </tr>
    </tr>
    <tr><td class="td27" colspan="2">折扣：</td></tr>
    <tr class="noborder">
        <td class="vtop rowform">$:form.discount.render() <font style="vertical-align:middle;">折</a></td>
        <td class="vtop tips2">折扣数取值范围0-10。</td>
    </tr>
    <tr><td class="td27" colspan="2">性价比指数：</td></tr>
    <tr class="noborder">
        <td class="vtop rowform">$:form.price_index.render()</td>
        <td class="vtop tips2">价格必须输入整数。</td>
    </tr>
    <tr><td class="td27" colspan="2">图片：</td></tr>
    <tr class="noborder">
        <td class="vtop rowform">
            $if form.media_id.value:
                <div id="thumbnail" class="thumb-3">
                    $ media_ids = form.media_id.value.split(',')
                    $for mid in media_ids:
                        <a href="javascript:;" title="重击删除" related="$mid"><img src="$:get_media_url(long(mid), 3)" /></a>
                </div>
            $else:
                <div id="thumbnail" style="display:none"></div>
            <a href="/admin/media/upload?thumb=3" class="_fancybox">设置特色图</a>$:form.media_id.render()</td>
        <td class="vtop tips2">点击“<a href="/admin/media/upload?thumb=3" class="_fancybox">设置特色图</a>”选择或上传特色图片</td>
    </tr>
    <!--
    <tr><td class="td27" colspan="2">简要说明：</td></tr>
    <tr class="noborder">
        <td class="vtop rowform">$:form.short_text.render()</td>
        <td class="vtop tips2">请简短的对灵感图进行说明，内容请控制在128个汉字，256个字符以内。</td>
    </tr>
    -->
    <tr><td class="td27" colspan="2">正文</td></tr>
    <tr>
        <td class="vtop rowform" colspan="2" style="border:1px #ddd solid">$:form.content.render()</td>
    </tr>
    <tr><td class="td27" colspan="2">出发城市</td></tr>
    <tr>
        <td class="vtop rowform">$:form.depart_id.render()</td>
        <td class="vtop tips2">可选，请选择特惠信息的出发城市。</td>
    </tr>
    <tr><td class="td27" colspan="2">关联合作商家：</td></tr>
    <tr class="noborder">
        <td class="vtop rowform">
            $if form.partner_name.value:
                <div id="spartner" style="height:25px;line-height:25px;">已选择：<font color="red"><strong>$:form.partner_name.value</strong></font></div>
            $else:
                <div id="spartner" style="display:none;height:25px;line-height:25px;"></div>
            <a href="$config.ADMIN_DIR/partner?mode=lite" class="_fancybox">设置关联合作商家</a>$:form.partner_id.render()</td>
        <td class="vtop tips2">您必须设置关联的合作方，标识此优惠信息的供应商。请重击“<a href="$config.ADMIN_DIR/partner?mode=lite" class="_fancybox">设置关联合作商家</a>”进行选择。</td>
    </tr>
    <tr><td class="td27" colspan="2">关联项目：</td></tr>
    <tr class="noborder">
        <td class="vtop rowform">
            $if form.proj_name.value:
                <div id="sproj" style="height:25px;line-height:25px;">已选择：<font color="red"><strong>$:form.proj_name.value</strong></font></div>
            $else:
                <div id="sproj" style="display:none;height:25px;line-height:25px;"></div>
            <a href="$config.ADMIN_DIR/proj?mode=lite" class="_fancybox">设置关联项目</a>$:form.proj_id.render()</td>
        <td class="vtop tips2">您必须设置关联的项目，请重击“<a href="$config.ADMIN_DIR/proj?mode=lite" class="_fancybox">设置关联项目</a>”进行选择。</td>
    </tr>
    <tr><td class="td27" colspan="2">关联灵感瀑布[可选]：</td></tr>
    <tr class="noborder">
        <td class="vtop rowform"><a href="javascript:;" onclick="alert('暂未开放！');">设置关联灵感瀑布</a>$:form.afflatus_id.render()</td>
        <td class="vtop tips2">关联灵感瀑布是一个可选项，如果您要设置请重击“<a href="javascript:;" onclick="alert('暂未开放！');">设置关联灵感瀑布</a>”进行选择。</td>
    </tr>
    <tr><td class="td27" colspan="2">预订提示[可选]</td></tr>
    <tr class="noborder">
        <td class="vtop rowform">$:form.booking_tips.render()</td>
        <td class="vtop tips2">此字段内容将显示在转向到供应商页面的链接旁，作为提示信息。限64个汉字以内。</td>
    </tr>
   <tr style="display:none"><td class="td27" colspan="2">关联比价项：</td></tr>
    <tr class="noborder" style="display:none">
        <td class="vtop rowform">
            <a id="related_comp_item" class="_fancybox"></a>$:form.related_comp_ids.render()</td>
        <td class="vtop tips2">设置关联比价信息，会在特惠详页显示与设置信息的最新价格的对比。</td>
    </tr> 
    <tr><td colspan="2">$:form.submit.render()</td></tr>
</table>
</form>

$:render.admin.tinymce_wplugin()

$:render.admin.footer()
